package site.shihuan.helpdesk.im.command.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import site.shihuan.helpdesk.im.SessionContextHolder;
import site.shihuan.helpdesk.im.command.BaseCommand;
import site.shihuan.helpdesk.im.exception.CommandException;
import site.shihuan.helpdesk.im.message.BaseMessage;
import site.shihuan.helpdesk.im.message.impl.RtcMessage;
import site.shihuan.helpdesk.security.context.UserContext;

import javax.websocket.Session;
import java.io.IOException;

/**
 * RTC Command
 *
 * @author 周世焕
 * @Date 2021/4/26 15:18
 */
@Component
public class RtcCommand implements BaseCommand {

    @Autowired
    private SessionContextHolder sessionContextHolder;

    @Override
    public void execute(Session session, BaseMessage message) throws CommandException, IOException {
        RtcMessage rtcMessage = (RtcMessage) message;
        rtcMessage.setLocal(sessionContextHolder.getUserId(session));
        sessionContextHolder.sendMessage(rtcMessage,rtcMessage.getRemote());
    }
}
